
(function($, win, doc){
	
	/**
	 *  默认值：/seeyon
	 */
	var appBasePath = (function(){
		
		var path = location.pathname;
		
		return path.substring(0, path.indexOf('/', 1));
	})();
	
	/**
	 * 获取 CTP TOP
	 */
	function getCtpTop(){
		
		function getCtpParentWindow(_window) {
			
		    var _win = _window;
		    
		    for (var i=0; i<20; i++) {
		    	
		        if (typeof _win.isCtpTop != "undefined" && _win.isCtpTop) {
		        	
		            return _win;
		            
		        } else {
		        	
		            if (_win == window.top) {
		                break;
		            }
		            
		            _win = _win.parent;
		        }
		    }
		}
		
		try {
			
	        var _win = getCtpParentWindow(win);
	        
	        if (_win) {
	        	
	            return _win;
	            
	        } else {
	            return top;
	        }
	    } catch (err) {
	        return top;
	    }
	}
		
	var app = new Vue({
		el: '#app',
		data: {
			basic:{

			},
			style:{
				
			},
			listData:[{
				id: null,
				name: '业务集成',
				icon: '&#xea43;',
				img: '',
				url: (appBasePath + '/plugin/development_platform/cip_create_business/index.html'),
				windowType: 'dialog',
				width: 450,
				height: 260
			},{
				id: null,
				name: '系统日志',
				icon: '&#xebd9;',
				img: '',
				url: (appBasePath + '/plugin/development_platform/logs/index.html'),
				windowType: 'dialog'
			},{
				id: null,
				name: '开放平台\r\n（ NEW ）',
				icon: '&#xe81f;',
				img: '',
				url: 'https://opendoc.seeyoncloud.com/bin/view/Main/',
				windowType: 'window'
			},{
				id: null,
				name: 'CIP集成平台',
				icon: '&#xe81f;',
				img: '',
				url: 'https://opendoc.seeyoncloud.com/bin/view/technology/categoryOfTechnology/t_cip',
				windowType: 'window'
			},{
				id: null,
				name: 'M3',
				icon: '&#xe81f;',
				img: '',
				url: 'https://opendoc.seeyoncloud.com/bin/view/technology/categoryOfTechnology/t_m3',
				windowType: 'window'
			},{
				id: null,
				name: '开放平台',
				icon: '&#xe81f;',
				img: '',
				url: 'http://open.seeyon.com',
				windowType: 'window'
			},{
				id: null,
				name: '在线二维码',
				icon: '&#xe69c;',
				img: '',
				url: 'https://tool.oschina.net/qr',
				windowType: 'window'
			},{
				id: null,
				name: '在线工具',
				icon: '&#xe81f;',
				img: '',
				url: 'https://tool.oschina.net/',
				windowType: 'window'
			}]
		},
		methods:{
			init: function(){
				
			},
			openWindow: function(index, type){
				
				if('window' == type){
					
					window.open(this.listData[index].url, '_blank');
					
				}else if('dialog' == type){

					this.openDialog(this.listData[index].name, this.listData[index].url, this.listData[index].width, this.listData[index].height);
				}
			},
			openDialog: function(title, src, width, height){
				
				window['SNAIL_MY_APP_WALL_DIALOG'] = getCtpTop().$.dialog({
			        id: 'SNAIL_MY_APP_WALL_DIALOG',
			        url: src,
			        width: (function(width){
						
			        	if(width && 100 < width){
			        		return width;
			        	}
			        	
						width = document.body.clientWidth;
							
						if(document.documentElement.clientWidth){
							width = document.documentElement.clientWidth;
						}
						
						return (width - 100);
					})(width),
			        height: (function(height){
						
			        	if(height && 180 < height){
			        		return height;
			        	}
			        	
						height = document.body.clientHeight;
						
						if(document.documentElement.clientHeight){
							height = document.documentElement.clientHeight;
						}
						
						return (height - 180);
					})(height),
			        title: title,
			        notCopyReturnValue: true,
			        targetWindow: getCtpTop(),
			        transParams: { },
			        buttons: [{
						text: '确认',
						id: "sure",
						isEmphasize: true,
						handler: function() {
							
							var result = SNAIL_MY_APP_WALL_DIALOG.getReturnValue();
							
							if($.isBlank(result)){
								
								;
								
							} else if('[object Promise]' === Object.prototype.toString.call(result)){
								
								result.then((_result) => {
									
									if (200 != _result.code) {
										
										_result.message && alert(_result.message);
										
									} else {
										
										_result.message && alert(_result.message);
										
										SNAIL_MY_APP_WALL_DIALOG.close();
									}
									
								}).catch( error => {
									
									alert(error);
								});	
								
							} else if (200 != result.code) {
								
								result.message && alert(result.message);
								
							} else {
								
								result.message && alert(result.message);
								
								SNAIL_MY_APP_WALL_DIALOG.close();
							}
						}
					},{
						text: '取消',
						id: "exit",
						handler: function() {
							SNAIL_MY_APP_WALL_DIALOG.close();
						}
					}]
			    });
			},
			isNotBlank: function(txt){
				return !$.isBlank(txt);
			}
		},
		created: function(){
			this.init();
		}
	});
	

})(Snail, window, document);




